////////////////////////////////////////////////////////////////////////////////
// This file is part of the Mist compiler.                                    //
//                                                                            //
// Copyright (C) 2008, 2009 The Mist project                                  //
//                                                                            //
// For a list of contributors, see the COMMITTERS file.                       //
//                                                                            //
// The Mist compiler is free software: you can redistribute it and/or modify  //
// it under the terms of the GNU General Public License as published by       //
// the Free Software Foundation, either version 3 of the License, or          //
// (at your option) any later version.                                        //
//                                                                            //
// The Mist compiler is distributed in the hope that it will be useful,       //
// but WITHOUT ANY WARRANTY; without even the implied warranty of             //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              //
// GNU General Public License for more details.                               //
//                                                                            //
// You should have received a copy of the GNU General Public License          //
// in the COPYING file. If not, see <http://www.gnu.org/licenses/>.           //
////////////////////////////////////////////////////////////////////////////////

///
/// \file
/// Contains includes and convenience functions that may be used by
/// the test-cases.
///

#ifndef TEST_COMMON_HPP
#define TEST_COMMON_HPP

////////////////////////////////////////////////////////////////////////////////
// Includes                                                                   //
////////////////////////////////////////////////////////////////////////////////

#include <vector>
using std::vector;

#include <ostream>
using std::ostream;

#include <boost/test/unit_test.hpp>

#include <boost/test/execution_monitor.hpp>

#include <boost/assign.hpp>
using namespace boost::assign;

#include "common/assert.hpp"

////////////////////////////////////////////////////////////////////////////////
// Convenience Functions                                                      //
////////////////////////////////////////////////////////////////////////////////

namespace {
	/// Functor struct that acts as the negation of the function variable f.
	///
	template<class F>
	struct not_t {
		template<class T>
		bool operator()(const T& t) {
			return !f(t);
		}
		
		template<class T1, class T2>
		bool operator()(const T1& t1, const T2& t2) {
			return !f(t1, t2);
		}
		
		template<class T1, class T2, class T3>
		bool operator()(const T1& t1, const T2& t2, const T3& t3) {
			return !f(t1, t2, t3);
		}
		
		F f;
	};
}

namespace std {
	/// Output a vector \a vec to a stream \a out.
	///
	/// \return \a out
	///
	template <class T>
	ostream& operator<<(ostream& out, const vector<T>& vec) {
		out << "[" << implode(vec, ",") << "]";
		
		return out;
	}
}

/// \return the negation of the function \a f such that !f(par) = neg(f)(par)
///
template<class F>
not_t<F> neg(F f) {
	not_t<F> result = { f };
	return result;
}

#endif // TEST_COMMON_HPP
